<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">

    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          rowKey="applicationDetailId"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange , type: checkval}"
          class="j-table-force-nowrap"
          @change="handleTableChange"/>
      </div>
    </a-card>

  </j-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'


export default {
  name: 'BussApplicationListModal',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  // props: ['category', "modalWidth",],
  props: {
    category: {
      type: String,
      default: ''
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250
    },
    checkval: {
      type: String,
      default: 'radio'
    }
  },
  watch: {
    category(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to:', newValue);
      this.queryParam = {id: newValue};
      this.loadData();
    }
  },
  data() {
    return {
      description: '供应商管理页面',
      visible: false,
      title: '选择供应商',
      queryParam: {id: this.category},
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '材料编号',
          dataIndex: 'materialCode',
        },
        {
          title: '材料名称',
          dataIndex: 'materialName',
        },
        {
          title: '规格',
          dataIndex: 'spec',
        },
        {
          title: '单位',
          dataIndex: 'unit',
        },
        {
          title: '数量',
          dataIndex: 'num',
        },
        {
          title: '到货日期',
          dataIndex: 'arrivalDate',
          width: 150,
        },
        {
          title: '用途',
          dataIndex: 'useDesc',
        },
      ],
      url: {
        list: "/plan/bussMaterialProcurementPlan/applicationDetail",
        delete: "/base/erpSupplier/delete",
        deleteBatch: "/base/erpSupplier/deleteBatch",
        exportXlsUrl: "/base/erpSupplier/exportXls",
        importExcelUrl: "base/erpSupplier/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleSubmit() {
      console.log("点击确定了")
      console.log('获取的数据',this.selectedRowKeys)
      this.getGoodsSupplierSelectRows();
      this.searchReset(false)
      this.onClearSelected();
      this.close();
    },
    add() {
      this.showModal();
    },
    showModal() {
      this.visible = true;
      this.loadData();
    },
    getGoodsSupplierSelectRows() {
      let selectedRow = null;
      if(this.checkval=='radio'){
         selectedRow = this.selectionRows[0];
      }else{
         selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit("applicationOk", selectedRow);
    },
    initDictConfig() {
    },
    close() {
      this.searchReset(false);
      this.visible = false;
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'materialCode', text: '材料编号', dictCode: ''})
      fieldList.push({type: 'string', value: 'materialName', text: '材料名称', dictCode: ''})
      fieldList.push({type: 'string', value: 'spec', text: '规格', dictCode: ''})
      fieldList.push({type: 'string', value: 'unit', text: '单位', dictCode: ''})
      fieldList.push({type: 'string', value: 'num', text: '数量', dictCode: ''})
      fieldList.push({type: 'string', value: 'arrivalDate', text: '到货日期', dictCode: ''})
      fieldList.push({type: 'string', value: 'useDesc', text: '用途', dictCode: ''})
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>